#include "systemcheck.h"
#define _WIN32_DCOM
#include <QOperatingSystemVersion>
#include <windows.h>
#include <QRenderCapabilities>
#include <QProcess>

SystemCheck::SysInfo SystemCheck::SInfo;//获取保存系统信息的变量
SystemCheck::SystemCheck(){}

bool SystemCheck::CheckCPU()
{
    QString cmd="wmic cpu get name\r\n";
    QProcess p;
    p.start("cmd.exe");
    p.write(cmd.toLatin1().data(),cmd.length());
    p.waitForFinished();
    QString result = QString::fromLocal8Bit(p.readAll());
    result.replace("\n","\r");
    QStringList list = result.split("\r");
    for(int i=0;i<list.length();i++){
        if (list[i].contains("Hz")){
            list[i]=list[i].simplified();
            SInfo.cpu_Info = list[i];
            break;
        }
    }
    return true;
}

bool SystemCheck::CheckGPU()
{
    Qt3DRender::QRenderCapabilities a;
    SInfo.GCardDriverVer=a.driverVersion();
    return true;
}

bool SystemCheck::CheckGPUDriver()
{
    return true;
}

bool SystemCheck::CheckSystem()
{
    if (QOperatingSystemVersion::currentType()!=QOperatingSystemVersion::Windows)
        return false;
    QOperatingSystemVersion currentOSVersion = QOperatingSystemVersion::current();
    if (currentOSVersion>=QOperatingSystemVersion(QOperatingSystemVersion::Windows,7)){
        SInfo.SysName="Windows " + QString::number(currentOSVersion.majorVersion());
        SInfo.SysBit=QSysInfo::WordSize;
        return true;
    }else{
        return false;
    }
}

bool SystemCheck::CheckMemory()
{
//    int GB = (1024 * 1024 * 1000);
//    MEMORYSTATUSEX statex;
//    statex.dwLength = sizeof (statex);
//    GlobalMemoryStatusEx (&statex);
//    SInfo.MemoryTotalSize=statex.ullTotalPhys/GB;
//    SInfo.MemoryAvailableSize=statex.ullAvailPhys/GB;
//    if (SInfo.MemoryTotalSize==0||SInfo.MemoryAvailableSize==0)return false;
    return true;
}

bool SystemCheck::CheckNet()
{
    return true;
}

bool SystemCheck::CheckVC()
{
    return true;
}

bool SystemCheck::CheckNetwork()
{
    //TODO
    return true;
}

bool SystemCheck::CheckDisk()
{
    //TODO
    return true;
}
